<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<strong><%@ taglib prefix="c"
                   uri="http://java.sun.com/jsp/jstl/core" %></strong>
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>轮播编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/xAdmin/css/font.css">
    <link rel="stylesheet" href="/xAdmin/css/xadmin.css">
    <link rel="stylesheet" href="/xAdmin/lib/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="/xAdmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/xAdmin/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form" lay-filter="example">
            <input type="hidden" value="${ca.id}" id="cid">
            <input type="hidden" value="${ca.context}" id="contextDesc">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${ca.name}">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="soft" class="layui-form-label">
                    序列
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="soft" name="soft" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="${ca.soft}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block" style="width: 100px">
                    <select name="cState" id="cState"  lay-verify="" >
                        <option value="0" <c:if test="${ca.cState=='0'}"> selected </c:if>
                        >发布</option>
                        <option value="1" <c:if test="${ca.cState=='1'}"> selected </c:if>
                        >失效</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="mainpicShowValue" class="layui-form-label">
                    <button type="button" class="layui-btn" id="file" name="file">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </label>
                <div class="layui-input-block">
                    <input type="hidden" id="mainpicShowValue" value="">
                    <img src="${ca.mainpic}" id="mainpicShow" >
                </div>
            </div>
            <div class="layui-form-item">
                <label for="context" class="layui-form-label">
                    新闻
                </label>
                <div class="layui-input-block" >
                    <textarea name="context"  id="context" lay-verify="content" ></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                </div>
            </div>

        </form>
    </div>
</div>
<script>




    layui.use(['form', 'layedit'], function(){
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var descs = $("#descriptiondesc").val();
        // form.val('example',{"description":descs});

        //富文本编辑器
        var layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '../ajaxData/uploadImage' //接口url
                ,type: 'post' //默认post
            }
        });
        var index = layedit.build('context'); //建立编辑器
        var contextDesc = $('#contextDesc').val();
        // if(contextDesc!=null&&contextDesc!="")
        //     layedit.setContent(index,$('#contextDesc').val());
        //提交时把值同步到文本域中
        form.verify({
            //content富文本域中的lay-verify值
            content: function(value) {
                return layedit.sync(index);
            }
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            var datas=null;
            var id =$("#cid").val();
            var name =  data.field.name;
            var soft =  data.field.soft;
            var context = data.field.context;
            var cState = $('#cState option:selected').val();
            var mainpic = $('#mainpicShowValue').val();
            if(id==null||id==""){
                datas = {
                    name:name,
                    soft:soft,
                    context:context,
                    cState:cState,
                    mainPic:mainpic
                };
            }else{
                datas = {
                    id:id,
                    name:name,
                    soft:soft,
                    context:context,
                    cState:cState,
                    mainPic:mainpic
                };
            }
            $.ajax({
                url:"/tBizCarouse/edit",
                type:'post',
                dataType:'text',
                contentType: 'application/json',
                data:JSON.stringify(datas),
                timeout:2000,
                success:function(data){
                    console.log(data);
                    var layer = parent.layui.layer;
                    if(data.oper_res == 'success')
                        layer.msg('操作成功!',{icon:1,time:1000});
                    else
                        layer.msg('操作失败!',{icon:1,time:1000});
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                },
                error:function () {
                    var layer = parent.layui.layer;
                    layer.msg("操作失败",{icon:1,time:1000});
                }
            });
            return false;
        });

    });


    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#file' //绑定元素
            ,url: '/ajaxData/uploadFile' //上传接口
            ,done: function(res){
                //上传完毕回调
                $("#mainpicShow").attr("src", res.srcPath);
                $("#mainpicShowValue").val(res.showPath);

            }
            ,error: function(){
                //请求异常回调
                console.log("请求异常回调");
            }
        });
    });





</script>

</body>

</html>
